<?php

/**
 * Description of loader
 *
 * @author user
 */
class Loader {

    /**
     * Load view
     * @param string $view file
     * @param array $vars variabel for view
     */
    public function view($view, $vars = '') {
        @ob_start();
        if (is_array($vars))
            $the_vars = extract($vars);

        include BASEPATH . '/views/' . $view . '.php';
        @ob_end_flush();
    }

    /**
     * Load Class Model
     *
     * @param   string  Table name
     * @param   string  Model name
     * @return  void
     */
    public function model($model, $name= '') {
        require_once BASEPATH . 'core/common.php';

        $c = & get_instance();

        if ($name == '') {
            $name = strtolower($model);
        }

        if (isset($c->$name)) { // name has used
            // No action
        } else {
            $filename = BASEPATH . 'models/' . strtolower($name) . '.php';

            if (file_exists($filename)) {
                require_once BASEPATH . 'core/model.php';
                require_once $filename;

                if(class_exists($model)) {
                    $c->$name = new $model();
                } else {
                    show_error("Error - Model class $model could not be found.");
                }
            } else {
                show_error("Error - Model file $model could not be found.");
            }
        }
    }

}

?>